package sg.edu.nus.iss.stockex;

import java.util.Date;

import sg.edu.nus.iss.Util;
public class StockQuote{
	private String code;
	private Date tradeDate;
	private String name;
	private double highPrice;
	private double lowPrice;
	private double openPrice;
	private double closePrice;
	private long volume;

	public StockQuote()
	{
		

	}

	public StockQuote(String code, Date tradeDate, String name, double highPrice,
			double lowPrice, double openPrice, double closePrice, long volume) {
		super();
		this.code = code;
		this.tradeDate = tradeDate;
		this.name = name;
		this.highPrice = highPrice;
		this.lowPrice = lowPrice;
		this.closePrice = closePrice;
		this.openPrice = openPrice;
		this.volume = volume;
	}

	/*public StockQuote(String strLine) {
		super();
		String [] words = strLine.split(";");
		
		this.code = words[7];
		this.tradeDate = Util.parseDate(words[0]);
		this.name = words[1];
		this.highPrice = Double.parseDouble(words[4]);
		this.lowPrice = Double.parseDouble(words[5]);
		this.closePrice = Double.parseDouble(words[6]);
		this.openPrice = Double.parseDouble(words[12]);
		this.volume = Long.parseLong(words[8]);
	}*/

	public static StockQuote parseString(String stockStr)
	{
		StockQuote stockQuote = null;
		try
		{
			String[] stockData = stockStr.split(";");
			System.out.println("text:" + stockData.toString());
			String name = stockData[1].trim();
			String code = stockData[14].trim();
			String dateStr = stockData[0].trim();
			Date date = Util.parseDate(dateStr.trim());
			double highPrice =	new Double(stockData[4].trim()).doubleValue();
			double lowPrice = new Double(stockData[5].trim()).doubleValue();
			double openPrice = new Double(stockData[12].trim()).doubleValue();
			double closePrice = new Double(stockData[6].trim()).doubleValue();
			long volume = new Long(stockData[8].trim()).longValue();
			stockQuote = new StockQuote(code, date, name, highPrice, lowPrice, openPrice, closePrice, volume);
		}catch(Exception ex)
		{
			return null;
		}

		return stockQuote;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Date getTradeDate() {
		return tradeDate;
	}

	public void setTradeDate(Date tradeDate) {
		this.tradeDate = tradeDate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getHighPrice() {
		return highPrice;
	}

	public void setHighPrice(double highPrice) {
		this.highPrice = highPrice;
	}

	public double getLowPrice() {
		return lowPrice;
	}

	public void setLowPrice(double lowPrice) {
		this.lowPrice = lowPrice;
	}

	public double getClosePrice() {
		return closePrice;
	}

	public void setClosePrice(double closePrice) {
		this.closePrice = closePrice;
	}

	public long getVolume() {
		return volume;
	}

	public void setVolume(long volume) {
		this.volume = volume;
	}

	
	public double getOpenPrice() {
		return openPrice;
	}

	public void setOpenPrice(double openPrice) {
		this.openPrice = openPrice;
	}

	public String getYearMonthTradeDate() {

		return Util.getYearMonth(this.tradeDate);

	}

	

	private long getLongTradeDate() {
		return tradeDate.getTime();
	}
	
}